package algorithm.view.maze.generation;

import java.util.ArrayList;

/**
 * @author bingo
 * @Description    随机队列
 * @Date 2018/6/10
 */
public class RandomQueue<E> {

   private ArrayList<E> queue;

    public RandomQueue() {
        queue = new ArrayList<>();
    }

    public void add(E e){
        queue.add(e);
    }

    public E removeElement(){
        int  randomIndex  = (int) (Math.random()*queue.size());
         E randElement =  queue.get(randomIndex);
         queue.set(randomIndex,queue.get(queue.size()-1));
         queue.remove(queue.size()-1);
         return  randElement;

    }

    public int size(){
        return queue.size();
    }

    public boolean isEmpty(){
        return  queue.size()==0;
    }



}


